package cn.o.app.io;

import android.content.Intent;
import android.os.Bundle;
import cn.o.app.json.JsonUtil;

public class Extra implements INoProguard {
	public static final String EXTRA_KEY = "extra";

	public Extra() {
		super();
	}

	public boolean getFrom(Intent intent) {
		try {
			JsonUtil.convert(intent.getStringExtra(EXTRA_KEY), this);
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	public boolean putTo(Intent intent) {
		try {
			intent.putExtra(EXTRA_KEY, JsonUtil.convert(this));
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	public boolean getFrom(Bundle bundle) {
		try {
			JsonUtil.convert(bundle.getString(EXTRA_KEY), this);
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	public boolean putTo(Bundle bundle) {
		try {
			bundle.putString(EXTRA_KEY, JsonUtil.convert(this));
			return true;
		} catch (Exception e) {
			return false;
		}
	}

}
